﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System.Net;
using System.Threading;

namespace OptiGear1
{
    public partial class Form1 : Form
    {
        private Optimiser optimiser;

        private List<WowClass> classes; //supported classes
        private List<WowItem> gear; //gets modified
        private List<WowItem> gearlist; //master list
        private List<WowItem> excludedItems;
        private List<WowItem> filteredItems;
        private List<WowItem> lockedItems;
        private List<WowItem> enhancements;
        private List<WowItem> trinkets;
        private List<WowGem> gems;
        private List<WeightProfile> profiles;

        private XmlDocument tierSets;

        private LinkLabel clickedLabel;
        private int clickedBodypart;
        private int[] lockedBodyParts;

        int targetHit; //to set by user
        double lostHitWeight;
        double t7_2pc;
        double t8_2pc;
        double t9_2pc;
        double t10_2pc;
        double t7_4pc; // NOT INCLUDING 2pc weight!
        double t8_4pc;
        double t9_4pc;
        double t10_4pc;

        double spellpower_weight;
        double haste_weight;
        double spirit_weight;
        double crit_weight;
        double intel_weight;
        double stamina_weight;

        private WowClass currentClass;
        
        public Form1()
        {
            InitializeComponent();

            minilvl.SelectedIndex = 0;
            maxilvl.SelectedIndex = maxilvl.Items.Count - 1;

            //load items from xml
            tierSets = new XmlDocument();
            tierSets.Load("tierSets.xml");
            classes = WowClass.Deserialize("classes.xml");
            profiles = WeightProfile.Deserialize("profiles_"+classes[0].Name+".xml");
            gearlist = WowItem.Deserialize("gearlist.xml");
            excludedItems = WowItem.Deserialize("excluded.xml");
            filteredItems = new List<WowItem>();
            trinkets = WowItem.Deserialize("trinkets.xml");
            enhancements = WowItem.Deserialize("itemEnhancements.xml");
            gems = WowGem.Deserialize("gems.xml");
            lockedItems = new List<WowItem>();

            //gearlist includes trinkets and enhancements/meta gems
            gearlist.AddRange(trinkets);
            gearlist.AddRange(enhancements);

            //add to 'included items list' all items which aren't excluded
            //todo - check why I used name instead of ID
            for (int i = 0; i < gearlist.Count; i++)
            {
                if (excludedItems.FindAll(delegate(WowItem w) { return w.name == gearlist[i].name; }).Count == 0)
                    listBox1.Items.Add(gearlist[i].name);
            }
            listBox1.Sorted = true;
            
            //add to 'excluded items list' all items which are excluded            
            for (int i = 0; i < excludedItems.Count; i++)
            {
                listBox2.Items.Add(excludedItems[i].name);
            }
            listBox2.Sorted = true;

            //load classes into combo box
            comboBox2.Items.Clear();
            for (int i = 0; i < classes.Count; i++)
            {
                comboBox2.Items.Add(classes[i].name);
            }
            comboBox2.SelectedIndex = 0;

            //load profiles into combo box
            comboBox1.Items.Clear();
            for (int i = 0; i < profiles.Count; i++)
            {
                comboBox1.Items.Add(profiles[i].name);
            }
            LoadProfileWeights(profiles[0]);
            comboBox1.SelectedIndex = 0;

            //initialise locked body parts array to nothing
            lockedBodyParts = new int[Utils.bodyparts.Length];
            for (int i = 0; i < lockedBodyParts.Length; i++)
            {
                lockedBodyParts[i] = 0;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;

            currentClass = classes[comboBox2.SelectedIndex];
            
            //now we start a new thread for the process
            Thread thread1 = new Thread(new ThreadStart(CalculateOptimalGearset));
            thread1.IsBackground = true;
            thread1.Start();
        }

        private void CalculateOptimalGearset()
        {
            #region get form values for weightings
            try
            {
                targetHit = Int32.Parse(targetHitBox.Text);
                spellpower_weight = Double.Parse(spellpowerBox.Text);
                haste_weight = Double.Parse(hasteBox.Text);
                spirit_weight = Double.Parse(spiritBox.Text);
                crit_weight = Double.Parse(critBox.Text);
                intel_weight = Double.Parse(intelBox.Text);
                stamina_weight = Double.Parse(staminaBox.Text);

                if (forceHit.Checked)
                {
                    lostHitWeight = 100;
                }
                else
                {
                    lostHitWeight = Double.Parse(lostHitBox.Text);
                }
                if (includeT7.Checked)
                {
                    t7_2pc = Double.Parse(t7_2pcBox.Text);
                    t7_4pc = Double.Parse(t7_4pcBox.Text);
                }
                else
                {
                    t7_2pc = 0.0;
                    t7_4pc = 0.0;
                }
                if (includeT8.Checked)
                {
                    t8_2pc = Double.Parse(t8_2pcBox.Text);
                    t8_4pc = Double.Parse(t8_4pcBox.Text);
                }
                else
                {
                    t8_2pc = 0.0;
                    t8_4pc = 0.0;
                }
                if (includeT9.Checked)
                {
                    t9_2pc = Double.Parse(t9_2pcBox.Text);
                    t9_4pc = Double.Parse(t9_4pcBox.Text);
                }
                else
                {
                    t9_2pc = 0.0;
                    t9_4pc = 0.0;
                }
                if (includeT10.Checked)
                {
                    t10_2pc = Double.Parse(t10_2pcBox.Text);
                    t10_4pc = Double.Parse(t10_4pcBox.Text);
                }
                else
                {
                    t10_2pc = 0.0;
                    t10_4pc = 0.0;
                }
            }
            catch (InvalidCastException)
            {
                if (label1.InvokeRequired)
                {
                    label1.Invoke(new MethodInvoker(delegate { label1.Text = "Invalid value supplied"; }));
                }
                if (button1.InvokeRequired)
                {
                    button1.Invoke(new MethodInvoker(delegate { button1.Enabled = true; }));
                }
                return;
            }
            #endregion

            optimiser = new Optimiser(targetHit, spellpower_weight, haste_weight, spirit_weight,
                    crit_weight, intel_weight, stamina_weight, lostHitWeight, t7_2pc, t7_4pc, t8_2pc, t8_4pc,
                    t9_2pc, t9_4pc, t10_2pc, t10_4pc);

            //create a list of all gear to include in the optimisation
            gear = new List<WowItem>();
            for (int i = 0; i < gearlist.Count; i++)
            {
                gear.Add(gearlist[i]);
            }

            //first, remove all excluded gear
            for (int i = 0; i < excludedItems.Count; i++)
            {
                gear.RemoveAll(delegate(WowItem w) { return w.name == excludedItems[i].name; });
            }

            //now remove all gear which this class cannot use
                
            switch(currentClass.Name)
            {
                case("warlock"):
                    {
                        gear.RemoveAll(delegate(WowItem w) { return w.warlock == false; });
                        break;
                    }
                case ("priest"):
                    {
                        gear.RemoveAll(delegate(WowItem w) { return w.priest == false; });
                        break;
                    }
                case ("mage"):
                    {
                        gear.RemoveAll(delegate(WowItem w) { return w.mage == false; });
                        break;
                    }
                default:
                    {
                        break;
                    }

            }
            //and weapons
            if (currentClass.OneHandedMaces == false)
                gear.RemoveAll(delegate(WowItem w) { return w.ItemClass == "Weapons" && w.Subclass == "One-Handed Maces"; });

            if (currentClass.OneHandedSwords == false)
                gear.RemoveAll(delegate(WowItem w) { return w.ItemClass == "Weapons" && w.Subclass == "One-Handed Sword"; });

            if (currentClass.Daggers == false)
                gear.RemoveAll(delegate(WowItem w) { return w.ItemClass == "Weapons" && w.Subclass == "Daggers"; });

            if (currentClass.Wands == false)
                gear.RemoveAll(delegate(WowItem w) { return w.ItemClass == "Weapons" && w.Subclass == "Wands"; });

            if (currentClass.Staves == false)
                gear.RemoveAll(delegate(WowItem w) { return w.ItemClass == "Weapons" && w.Subclass == "Staves"; });
  
            //optimise it
            optimiser.Optimise(gear, gems, lockedBodyParts, lockedItems);
            while (optimiser.Progress < 100)
            {
                Thread.Sleep(200); //check every half second
                if (progressBar1.InvokeRequired)
                {
                    progressBar1.Invoke(new MethodInvoker(delegate { progressBar1.Visible = true; }));
                    progressBar1.Invoke(new MethodInvoker(delegate { progressBar1.Value = (int)optimiser.Progress; }));
                }
                if (label1.InvokeRequired)
                {
                    //label1.Invoke(new MethodInvoker(delegate { label1.Text = newText; }));
                }
            }
            if (progressBar1.InvokeRequired)
            {
                progressBar1.Invoke(new MethodInvoker(delegate { progressBar1.Visible = false; }));
            }
            
            //reload gear to get values from
            gear = WowItem.Deserialize("gearlist.xml");
            trinkets = WowItem.Deserialize("trinkets.xml");

            gear.AddRange(trinkets);
            List<Gearset> gearset = optimiser.GearsetList;

            WowItem head = gear.Find(delegate(WowItem w) { return w.wowheadid == gearset[0].partIDs[Utils.HEAD]; });
            WowItem neck = gear.Find(delegate(WowItem w) { return w.wowheadid == gearset[0].partIDs[Utils.NECK]; });
            WowItem shoulder = gear.Find(delegate(WowItem w) { return w.wowheadid == gearset[0].partIDs[Utils.SHOULDER]; });
            WowItem back = gear.Find(delegate(WowItem w) { return w.wowheadid == gearset[0].partIDs[Utils.BACK]; });
            WowItem chest = gear.Find(delegate(WowItem w) { return w.wowheadid == gearset[0].partIDs[Utils.CHEST]; });
            WowItem wrist = gear.Find(delegate(WowItem w) { return w.wowheadid == gearset[0].partIDs[Utils.WRIST]; });

            SetLinkLabel(headLabel, gearset[0].partIDString[Utils.HEAD]);
            SetLinkLabel(neckLabel, gearset[0].partIDString[Utils.NECK]);
            SetLinkLabel(shoulderLabel, gearset[0].partIDString[Utils.SHOULDER]);
            SetLinkLabel(backLabel, gearset[0].partIDString[Utils.BACK]);
            SetLinkLabel(chestLabel, gearset[0].partIDString[Utils.CHEST]);
            SetLinkLabel(wristLabel, gearset[0].partIDString[Utils.WRIST]);

            WowItem hands = gear.Find(delegate(WowItem w) { return w.wowheadid == gearset[0].partIDs[Utils.HANDS]; });
            WowItem waist = gear.Find(delegate(WowItem w) { return w.wowheadid == gearset[0].partIDs[Utils.WAIST]; });
            WowItem legs = gear.Find(delegate(WowItem w) { return w.wowheadid == gearset[0].partIDs[Utils.LEGS]; });
            WowItem feet = gear.Find(delegate(WowItem w) { return w.wowheadid == gearset[0].partIDs[Utils.FEET]; });
            WowItem ring1 = gear.Find(delegate(WowItem w) { return w.wowheadid == gearset[0].partIDs[Utils.RING1]; });
            WowItem ring2 = gear.Find(delegate(WowItem w) { return w.wowheadid == gearset[0].partIDs[Utils.RING2]; });

            SetLinkLabel(handsLabel, gearset[0].partIDString[Utils.HANDS]);
            SetLinkLabel(waistLabel, gearset[0].partIDString[Utils.WAIST]);
            SetLinkLabel(legsLabel, gearset[0].partIDString[Utils.LEGS]);
            SetLinkLabel(feetLabel, gearset[0].partIDString[Utils.FEET]);
            SetLinkLabel(ringLabel1, gearset[0].partIDString[Utils.RING1]);
            SetLinkLabel(ringLabel2, gearset[0].partIDString[Utils.RING2]);

            WowItem weapon = gear.Find(delegate(WowItem w) { return w.wowheadid == gearset[0].partIDs[Utils.WEAPON]; });
            WowItem weapon2h = gear.Find(delegate(WowItem w) { return w.wowheadid == gearset[0].partIDs[Utils.TWOHANDED]; });
            WowItem offhand = gear.Find(delegate(WowItem w) { return w.wowheadid == gearset[0].partIDs[Utils.OFFHAND]; });
            WowItem ranged = gear.Find(delegate(WowItem w) { return w.wowheadid == gearset[0].partIDs[Utils.RANGED]; });
            WowItem handsEnchant = enhancements.Find(delegate(WowItem w) { return w.wowheadid == gearset[0].partIDs[Utils.HANDSENCHANT]; });
            WowItem feetEnchant = enhancements.Find(delegate(WowItem w) { return w.wowheadid == gearset[0].partIDs[Utils.FEETENCHANT]; });
            WowItem weaponEnchant = enhancements.Find(delegate(WowItem w) { return w.wowheadid == gearset[0].partIDs[Utils.WEAPONENCHANT]; });
            WowItem trinket1 = gear.Find(delegate(WowItem w) { return w.wowheadid == gearset[0].partIDs[Utils.TRINKET1]; });
            WowItem trinket2 = gear.Find(delegate(WowItem w) { return w.wowheadid == gearset[0].partIDs[Utils.TRINKET2]; });
            WowItem meta = gear.Find(delegate(WowItem w) { return w.wowheadid == gearset[0].partIDs[Utils.META]; });

            SetLinkLabel(weaponLabel, gearset[0].partIDString[Utils.WEAPON]);
            SetLinkLabel(weapon2hLabel, gearset[0].partIDString[Utils.TWOHANDED]);
            SetLinkLabel(offhandLabel, gearset[0].partIDString[Utils.OFFHAND]);
            SetLinkLabel(rangedLabel, gearset[0].partIDString[Utils.RANGED]);
            SetLinkLabel(handsEnchantLabel, gearset[0].partIDString[Utils.HANDSENCHANT]);
            SetLinkLabel(feetEnchantLabel, gearset[0].partIDString[Utils.FEETENCHANT]);
            SetLinkLabel(weaponEnchantLabel, gearset[0].partIDString[Utils.WEAPONENCHANT]);
            SetLinkLabel(trinketLabel1, gearset[0].partIDString[Utils.TRINKET1]);
            SetLinkLabel(trinketLabel2, gearset[0].partIDString[Utils.TRINKET2]);
            SetLinkLabel(metaLabel, gearset[0].partIDString[Utils.META]);

            if (label1.InvokeRequired)
            {
                label1.Invoke(new MethodInvoker(delegate { label1.Text = "Total hit: " + gearset[0].originalhit + "     Total weight: " + gearset[0].GetModifiedWeight(t7_2pc, t7_4pc, t8_2pc, t8_4pc, t9_2pc, t9_4pc, t10_2pc, t10_4pc, targetHit, lostHitWeight); }));
            }



            //DONE:
            //#Pick best one for specified hit rating
            //#incorporate the other stats missed
            //#check hit rating tally is correct
            //#Display it in a meaningful manner
            //#2 rings
            //#allow for 2h weapon instead of MH/OH
            //#incorporate gems!
            //#include meta gems & meta calculations            
            //#incorporate enchants
            //#incorporate trinkets
            //#allow T7/T8 bonuses
            //#hit/other coefficients to be configured
            //#allow pieces to be excluded 
            //#right click exclude
            //#socket bonus hit needs to show

            //TODO
            //Save custom weights
            //disable/enable loot by boss and by 10/25 man
            //search filter on exclude screen
            //classic display format
            //mouseover tooltips - item stats preview
            //check bug icecorestaff 2h, did not allow enchant?
            //allow higher hit rating (450 instead of 400)#
            //updated scaling factors/trinkets
            //export gear list
            //show source of item
            //BUG small lists don't seem to completely work.


            //allow BS sockets
            //allow JC gems        
            //have a snazzy display with icons & stuff
            //have weights or gear downloads saved in 'profiles'.




            //WriteGearToFile(items[0], "geartest.xml"); 
            if (button1.InvokeRequired)
            {
                button1.Invoke(new MethodInvoker(delegate { button1.Enabled = true; }));
            }
            //label1.Text += "Now " + items[0].Count;
        }

        private void SetLinkLabel(LinkLabel label, string wowheadids)
        {
            string labelText;
            if (String.IsNullOrEmpty(wowheadids))
            {
                labelText = "N/A";
                if (label.InvokeRequired)
                {
                    label.Invoke(new MethodInvoker(delegate { label.Text = labelText; }));
                }
                return;
            }
            string[] ids = wowheadids.Split(new char[] { '_' });
            labelText = "";
            int hit = 0;
            WowItem item = new WowItem();
            for (int i = 0; i < ids.Length; i++)
            {
                if (i == 0)
                {
                    item = gear.Find(delegate(WowItem w) { return w.wowheadid == Int32.Parse(ids[i]); });
                    if (item == null)
                        item = enhancements.Find(delegate(WowItem w) { return w.wowheadid == Int32.Parse(ids[i]); });
                    
                    hit += item.hit;
                    labelText += item.name;
                }
                else
                {
                    WowGem gem = gems.Find(delegate(WowGem w) { return w.wowheadid == Int32.Parse(ids[i]); });
                    hit += gem.hit;
                    labelText += " + " + gem.name;
                }
            }
            
            labelText = "["+hit+"] " + labelText;
            if (label.InvokeRequired)
            {
                label.Invoke(new MethodInvoker(delegate { label.Text = labelText; }));
            }
            label.Links[0].LinkData = Utils.wowheadprefix + item.wowheadid;
        }


        private void button2_Click(object sender, EventArgs e)
        {
            //Alright, the user clicked to load wowhead stuff
            //so first we disable the button
            button2.Enabled = false;
            
            //now we start a new thread for the process
            Thread thread1 = new Thread(new ThreadStart(LoadAllWowheadItems));
            thread1.IsBackground = true;
            thread1.Start();
        }

        private void LoadAllWowheadItems()
        {
            //this button gets gear from wowhead and saves it into our xml format, ready to use.
            
            //string bootsURL = "http://www.wowhead.com/?items=4.1&filter=sl=8;minle=200;ub=9"; //29
            //string headsURL = "http://www.wowhead.com/?items=4.1&filter=sl=1;minle=200;ub=9"; //27
            //string chestURL = "http://www.wowhead.com/?items=4.1&filter=sl=5;minle=200;ub=9"; //33
            //string handsURL = "http://www.wowhead.com/?items=4.1&filter=sl=10;minle=200;ub=9"; //32
            //string legsURL = "http://www.wowhead.com/?items=4.1&filter=sl=7;minle=200;ub=9"; //27
            //string shoulderURL = "http://www.wowhead.com/?items=4.1&filter=sl=3;minle=200;ub=9"; //24
            //string waistURL = "http://www.wowhead.com/?items=4.1&filter=sl=6;minle=200;ub=9"; //36
            //string wristURL = "http://www.wowhead.com/?items=4.1&filter=sl=9;minle=200;ub=9"; //27
            //string neckURL = "http://www.wowhead.com/?items=4&filter=sl=2;minle=200;ub=9;cr=123;crs=1;crv=50"; //43
            //string backURL = "http://www.wowhead.com/?items=4&filter=sl=16;minle=200;ub=9;cr=123;crs=1;crv=0"; //40
            //string weaponURL = "http://www.wowhead.com/?items=2&filter=sl=21;minle=200;ub=9"; //22
            //string weapon2URL = "http://www.wowhead.com/?items=2&filter=sl=15;minle=200;ub=9"; //23
            //string weapon2hURL = "http://www.wowhead.com/?items=2&filter=sl=17;minle=200;ub=9";
            //string offhandURL = "http://www.wowhead.com/?items&filter=sl=23;minle=200;ub=9"; //26
            //string ringsURL = "http://www.wowhead.com/?items&filter=sl=11;minle=200;ub=9";

            //CLOTH ONLY FOR NOW - will probably need separate files for others anyway.
            string bootsURL = "http://www.wowhead.com/?items=4&filter=sl=8;ty=1;minle=232";
            string headsURL = "http://www.wowhead.com/?items=4&filter=sl=1;ty=1;minle=232";
            string chestURL = "http://www.wowhead.com/?items=4&filter=sl=5;ty=1;minle=232";
            string handsURL = "http://www.wowhead.com/?items=4&filter=sl=10;ty=1;minle=232";
            string legsURL = "http://www.wowhead.com/?items=4&filter=sl=7;ty=1;minle=232";
            string shoulderURL = "http://www.wowhead.com/?items=4&filter=sl=3;ty=1;minle=232";
            string waistURL = "http://www.wowhead.com/?items=4&filter=sl=6;ty=1;minle=232";
            string wristURL = "http://www.wowhead.com/?items=4&filter=sl=9;ty=1;minle=232";
            string neckURL = "http://www.wowhead.com/?items=4&filter=sl=2;ty=-3;minle=232";
            string backURL = "http://www.wowhead.com/?items=4&filter=sl=16;ty=-6;minle=232";
            string weaponURL = "http://www.wowhead.com/?items=2&filter=sl=21;minle=232"; //main hand
            string weapon2URL = "http://www.wowhead.com/?items=2&filter=sl=15;minle=232"; //ranged           
            string weapon2hURL = "http://www.wowhead.com/?items=2&filter=sl=17;minle=232"; //two handed
            string offhandURL = "http://www.wowhead.com/?items&filter=sl=23;minle=232";
            string ringsURL = "http://www.wowhead.com/?items=4.-2&filter=minle=232";
            string raregemsURL = "http://www.wowhead.com/?items=3&filter=qu=4;ty=0:1:2:3:4:5;minle=80;cr=81;crs=5;crv=0";

            List<int> gemids = new List<int>();
            gemids.AddRange(WowheadParser.LoadItemsFromUrl(raregemsURL));
            //throw new Exception(gemids.Count + " gems found");
            List<WowGem> gems = new List<WowGem>();
            for (int i = 0; i < gemids.Count; i++)
            {
                if (label1.InvokeRequired)
                {
                    label1.Invoke(new MethodInvoker(delegate { label1.Text = "Loading Gems... " + (100 * i / gemids.Count) + "%"; }));
                }
                gems.Add(new WowGem(gemids[i]));
            }

            //now write them all to file
            WowGem.Serialize(gems, "gems.xml");

            //return;
            

            //now all other items
            string loadmsg = "Loading Items... ";
            if (label1.InvokeRequired)
            {
                label1.Invoke(new MethodInvoker(delegate { label1.Text = loadmsg; }));
            }

            List<int> items = new List<int>();
            items.AddRange(WowheadParser.LoadItemsFromUrl(bootsURL));
            items.AddRange(WowheadParser.LoadItemsFromUrl(headsURL));
            items.AddRange(WowheadParser.LoadItemsFromUrl(chestURL));
            items.AddRange(WowheadParser.LoadItemsFromUrl(handsURL));
            items.AddRange(WowheadParser.LoadItemsFromUrl(legsURL));
            items.AddRange(WowheadParser.LoadItemsFromUrl(shoulderURL));
            items.AddRange(WowheadParser.LoadItemsFromUrl(waistURL));
            items.AddRange(WowheadParser.LoadItemsFromUrl(wristURL));
            items.AddRange(WowheadParser.LoadItemsFromUrl(neckURL));
            items.AddRange(WowheadParser.LoadItemsFromUrl(backURL));
            items.AddRange(WowheadParser.LoadItemsFromUrl(weaponURL));
            items.AddRange(WowheadParser.LoadItemsFromUrl(weapon2URL));
            items.AddRange(WowheadParser.LoadItemsFromUrl(weapon2hURL));
            items.AddRange(WowheadParser.LoadItemsFromUrl(offhandURL));
            items.AddRange(WowheadParser.LoadItemsFromUrl(ringsURL));

            
            List<WowItem> wowitems = new List<WowItem>();
            for (int i = 0; i < items.Count; i++)
            {
                wowitems.Add(new WowItem(items[i], tierSets));
                //label1.Text = 
                if (label1.InvokeRequired)
                {
                    label1.Invoke(new MethodInvoker(delegate { label1.Text = loadmsg + (100 * i / items.Count) + "%"; }));
                }
            }
            
            //now write them all to file
            WowItem.Serialize(wowitems, "gearlist.xml");

            if (label1.InvokeRequired)
            {
                label1.Invoke(new MethodInvoker(delegate { label1.Text = "Items Loaded"; }));
            }
            if (button2.InvokeRequired)
            {
                button2.Invoke(new MethodInvoker(delegate { button2.Enabled = true; }));
            }    
        }

        #region itemclick links
        private void GoToLink(object sender, LinkLabelLinkClickedEventArgs e)
        {
            try
            {
                if (e.Button != MouseButtons.Right)
                    System.Diagnostics.Process.Start(e.Link.LinkData.ToString());
            }
            catch (Exception)
            {
                //no link to go to, do nothing
            }
        }

        private void headLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            GoToLink(sender, e);
        }

        private void metaLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            GoToLink(sender, e);
        }

        private void neckLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            GoToLink(sender, e);
        }

        private void shoulderLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            GoToLink(sender, e);
        }

        private void backLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            GoToLink(sender, e);
        }

        private void chestLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            GoToLink(sender, e);
        }

        private void waistLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            GoToLink(sender, e);
        }

        private void wristLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            GoToLink(sender, e);
        }

        private void weapon2hLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            GoToLink(sender, e);
        }

        private void weaponLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            GoToLink(sender, e);
        }

        private void weaponEnchantLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            GoToLink(sender, e);
        }

        private void offhandLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            GoToLink(sender, e);
        }

        private void rangedLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            GoToLink(sender, e);
        }

        private void handsLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            GoToLink(sender, e);
        }

        private void handsEnchantLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            GoToLink(sender, e);
        }

        private void legsLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            GoToLink(sender, e);
        }

        private void feetLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            GoToLink(sender, e);
        }

        private void feetEnchantLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            GoToLink(sender, e);
        }

        private void ringLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            GoToLink(sender, e);
        }

        private void ringLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            GoToLink(sender, e);
        }

        private void trinketLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            GoToLink(sender, e);
        }

        private void trinketLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            GoToLink(sender, e);
        }
        #endregion

        private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
        {
            this.contextMenuStrip1.Items.Clear();

            clickedLabel = (LinkLabel)contextMenuStrip1.SourceControl;
            //clickedBodypart = 0;

            if (contextMenuStrip1.SourceControl == headLabel)
            {
                clickedBodypart = Utils.HEAD;
            }
            else if (contextMenuStrip1.SourceControl == metaLabel)
            {
                clickedBodypart = Utils.META;
            }
            else if (contextMenuStrip1.SourceControl == neckLabel)
            {
                clickedBodypart = Utils.NECK;
            }
            else if (contextMenuStrip1.SourceControl == shoulderLabel)
            {
                clickedBodypart = Utils.SHOULDER;
            }
            else if (contextMenuStrip1.SourceControl == backLabel)
            {
                clickedBodypart = Utils.BACK;
            }
            else if (contextMenuStrip1.SourceControl == chestLabel)
            {
                clickedBodypart = Utils.CHEST;
            }
            else if (contextMenuStrip1.SourceControl == waistLabel)
            {
                clickedBodypart = Utils.WAIST;
            }
            else if (contextMenuStrip1.SourceControl == wristLabel)
            {
                clickedBodypart = Utils.WRIST;
            }
            else if (contextMenuStrip1.SourceControl == weapon2hLabel)
            {
                clickedBodypart = Utils.TWOHANDED;
            }
            else if (contextMenuStrip1.SourceControl == weaponLabel)
            {
                clickedBodypart = Utils.WEAPON;
            }
            else if (contextMenuStrip1.SourceControl == weaponEnchantLabel)
            {
                clickedBodypart = Utils.WEAPONENCHANT;
            }
            else if (contextMenuStrip1.SourceControl == offhandLabel)
            {
                clickedBodypart = Utils.OFFHAND;
            }
            else if (contextMenuStrip1.SourceControl == rangedLabel)
            {
                clickedBodypart = Utils.RANGED;
            }
            else if (contextMenuStrip1.SourceControl == handsLabel)
            {
                clickedBodypart = Utils.HANDS;
            }
            else if (contextMenuStrip1.SourceControl == handsEnchantLabel)
            {
                clickedBodypart = Utils.HANDSENCHANT;
            }
            else if (contextMenuStrip1.SourceControl == legsLabel)
            {
                clickedBodypart = Utils.LEGS;
            }
            else if (contextMenuStrip1.SourceControl == feetLabel)
            {
                clickedBodypart = Utils.FEET;
            }
            else if (contextMenuStrip1.SourceControl == feetEnchantLabel)
            {
                clickedBodypart = Utils.FEETENCHANT;
            }
            else if (contextMenuStrip1.SourceControl == ringLabel1)
            {
                clickedBodypart = Utils.RING1;
            }
            else if (contextMenuStrip1.SourceControl == ringLabel2)
            {
                clickedBodypart = Utils.RING2;
            }
            else if (contextMenuStrip1.SourceControl == trinketLabel1)
            {
                clickedBodypart = Utils.TRINKET1;
            }
            else if (contextMenuStrip1.SourceControl == trinketLabel2)
            {
                clickedBodypart = Utils.TRINKET2;
            }


            if (clickedLabel.LinkColor == Color.Red)
            {
                this.contextMenuStrip1.Items.Add("Unlock", null, new System.EventHandler(this.Unlock_OnClick)); 
            }
            else
            {
                WowItem wowitem = gearlist.Find(delegate(WowItem w) { return w.name == ((LinkLabel)contextMenuStrip1.SourceControl).Text; });

                if (((LinkLabel)contextMenuStrip1.SourceControl).Links[0].LinkData != null || wowitem != null)
                {
                    this.contextMenuStrip1.Items.Add("Lock current item as " + Utils.bodyparts[clickedBodypart]); //, null, new ToolStripItemClickedEventHandler(this.Lock_OnClick));
                }
            }

            ToolStripMenuItem item = new ToolStripMenuItem("Lock alternative item as " + Utils.bodyparts[clickedBodypart]);
            List<WowItem> matches = new List<WowItem>();
            matches = gearlist.FindAll(delegate(WowItem w) { return w.bodypart == Utils.bodyparts[clickedBodypart]; });
            matches.Sort(new WowItemNameComparer());
            for (int i = 0; i < matches.Count; i++)
            {
                //customise for each body part, or can we use the same method?                
                item.DropDownItems.Add(matches[i].name, null, new System.EventHandler(this.Lock_CustomClick));
            }
            contextMenuStrip1.Items.Add(item);
            contextMenuStrip1.ItemClicked += new ToolStripItemClickedEventHandler(Lock_OnClick);
        }

        #region lock/unlock items functions
        protected void Lock_CustomClick(object sender, System.EventArgs e)
        {
            ToolStripMenuItem item = (ToolStripMenuItem)sender;
            clickedLabel.Text = item.Text;
            clickedLabel.LinkColor = Color.Red;
            lockedItems.Add(gearlist.Find(delegate(WowItem w) { return w.name == item.Text; }));
            lockedBodyParts[clickedBodypart] = gearlist.Find(delegate(WowItem w) { return w.name == item.Text; }).wowheadid;

            CheckWeaponConflict();
        }

        protected void Unlock_OnClick(object sender, System.EventArgs e)
        {
            lockedBodyParts[clickedBodypart] = 0;
            ((LinkLabel)contextMenuStrip1.SourceControl).LinkColor = Color.Blue;
            lockedItems.RemoveAll(delegate(WowItem w) { return w.wowheadid == lockedBodyParts[clickedBodypart]; });
        }

        protected void Lock_OnClick(object sender, ToolStripItemClickedEventArgs e)
        {
            //BOLLOCKS, FIX THIS!
            string wowheadid;
            try
            {
                wowheadid = ((LinkLabel)contextMenuStrip1.SourceControl).Links[0].LinkData.ToString().Split(new char[] { '=' })[1];
            }
            catch (Exception) //todo proper exception catching
            {
                try
                {
                    WowItem item = gearlist.Find(delegate(WowItem w) { return w.name == ((LinkLabel)contextMenuStrip1.SourceControl).Text; });
                    if (item == null)
                    {
                        return;
                    }
                    else
                    {
                        wowheadid = item.wowheadid.ToString();
                    }
                }
                catch (Exception)
                {
                    return;
                }
            }
            lockedItems.Add(gearlist.Find(delegate(WowItem w) { return w.wowheadid == Int32.Parse(wowheadid); }));
            lockedBodyParts[clickedBodypart] = Int32.Parse(wowheadid);
            ((LinkLabel)contextMenuStrip1.SourceControl).LinkColor = Color.Red;

            CheckWeaponConflict();
        }

        private void CheckWeaponConflict()
        {
            WowItem weaponEnchant = gearlist.Find(delegate(WowItem w) { return w.wowheadid == lockedBodyParts[Utils.WEAPONENCHANT]; });
            WowItem weapon = gearlist.Find(delegate(WowItem w) { return w.wowheadid == lockedBodyParts[Utils.WEAPON]; });
            WowItem weapon2h = gearlist.Find(delegate(WowItem w) { return w.wowheadid == lockedBodyParts[Utils.TWOHANDED]; });
            bool clearweapon = false;
            bool clearweapon2h = false;
            bool clearweaponenchant = false;

            //check for weapon/2h/weaponenchant
            if (clickedBodypart == Utils.TWOHANDED)
            {
                //wipe any 1h weapon lock
                if (weapon != null)
                    clearweapon = true;

                //wipe staff enchant lock if this isn't a staff
                if (weapon2h.subclass != "Staves" && weaponEnchant.isStaffEnchant)
                    clearweaponenchant = true;
            }
            else if (clickedBodypart == Utils.WEAPONENCHANT && weaponEnchant.isStaffEnchant)
            {
                //if this is a staff enchant, wipe any 1h + any non-staff 2h
                if (weapon != null)
                    clearweapon = true;

                if (weapon2h != null && weapon.subclass != "Staves")
                    clearweapon2h = true;            
            }
            else if (clickedBodypart == Utils.WEAPON)
            {
                //wipe any 2h lock, or any staff enchant lock
                if (weapon2h != null)
                    clearweapon2h = true;

                if (weaponEnchant != null && weaponEnchant.isStaffEnchant)
                    clearweaponenchant = true;
            }

            if (clearweapon)
            {
                weaponLabel.LinkColor = Color.Blue;
                lockedItems.RemoveAll(delegate(WowItem w) { return w.wowheadid == lockedBodyParts[Utils.WEAPON]; });
                lockedBodyParts[Utils.WEAPON] = 0;
            }
            if (clearweaponenchant)
            {
                weaponEnchantLabel.LinkColor = Color.Blue;
                lockedItems.RemoveAll(delegate(WowItem w) { return w.wowheadid == lockedBodyParts[Utils.WEAPONENCHANT]; });
                lockedBodyParts[Utils.WEAPONENCHANT] = 0;
            }
            if (clearweapon2h)
            {
                weapon2hLabel.LinkColor = Color.Blue;
                lockedItems.RemoveAll(delegate(WowItem w) { return w.wowheadid == lockedBodyParts[Utils.TWOHANDED]; });
                lockedBodyParts[Utils.TWOHANDED] = 0;
            } 

        }
        #endregion

        #region load profiles
        private void LoadProfileWeights(WeightProfile profile)
        {
            targetHit = profile.targetHit;
            lostHitWeight = profile.lostHit;
            t7_2pc = profile.t7_2pc;
            t8_2pc = profile.t8_2pc;
            t9_2pc = profile.t9_2pc;
            t7_4pc = profile.t7_4pc; // NOT INCLUDING 2pc weight!
            t8_4pc = profile.t8_4pc;
            t9_4pc = profile.t9_4pc;
            t10_2pc = profile.t10_2pc;
            t10_4pc = profile.t10_4pc;
            spellpower_weight = profile.spellpower;
            stamina_weight = profile.stamina;
            haste_weight = profile.haste;
            spirit_weight = profile.spirit;
            crit_weight = profile.crit;
            intel_weight = profile.intel;
            includeT7.Checked = profile.includeT7;
            includeT8.Checked = profile.includeT8;
            includeT9.Checked = profile.includeT9;
            includeT10.Checked = profile.includeT10;
            forceHit.Checked = profile.forceHit;

            targetHitBox.Text = targetHit.ToString();
            spellpowerBox.Text = spellpower_weight.ToString();
            staminaBox.Text = stamina_weight.ToString();
            hasteBox.Text = haste_weight.ToString();
            spiritBox.Text = spirit_weight.ToString();
            critBox.Text = crit_weight.ToString();
            intelBox.Text = intel_weight.ToString();

            lostHitBox.Text = lostHitWeight.ToString();
            t7_2pcBox.Text = t7_2pc.ToString();
            t8_2pcBox.Text = t8_2pc.ToString();
            t9_2pcBox.Text = t9_2pc.ToString();
            t10_2pcBox.Text = t10_2pc.ToString();
            t7_4pcBox.Text = t7_4pc.ToString();
            t8_4pcBox.Text = t8_4pc.ToString();
            t9_4pcBox.Text = t9_4pc.ToString();
            t10_4pcBox.Text = t10_4pc.ToString();
        }
        #endregion

        #region include/exclude items events
        private void excludeAllbutton_Click(object sender, EventArgs e)
        {
            while (listBox1.Items.Count > 0)
            {
                string itemname = listBox1.Items[0].ToString();
                listBox1.Items.RemoveAt(0);
                listBox1.Sorted = true;

                WowItem item = gearlist.Find(delegate(WowItem w) { return w.name == itemname; });
                excludedItems.Add(item);
                listBox2.Items.Add(item.name);
                listBox2.Sorted = true;
            }
            WowItem.Serialize(excludedItems, "excluded.xml"); 
        }

        private void includeAllButton_Click(object sender, EventArgs e)
        {
            while (listBox2.Items.Count > 0)
            {
                string itemname = listBox2.Items[0].ToString();
                listBox2.Items.RemoveAt(0);
                listBox2.Sorted = true;

                WowItem item = excludedItems.Find(delegate(WowItem w) { return w.name == itemname; });
                excludedItems.Remove(item);
                listBox1.Items.Add(item.name);

                listBox1.Sorted = true;    
            }
            WowItem.Serialize(excludedItems, "excluded.xml");
        }

        private void listBox1_MouseDoubleClick_1(object sender, MouseEventArgs e)
        {
            int index = listBox1.IndexFromPoint(e.Location);
            if (index != -1)
            {
                string itemname = listBox1.Items[index].ToString();
                listBox1.Items.RemoveAt(index);
                listBox1.Sorted = true;

                WowItem item = gearlist.Find(delegate(WowItem w) { return w.name == itemname; });
                excludedItems.Add(item);
                listBox2.Items.Add(item.name);
                listBox2.Sorted = true;

                WowItem.Serialize(excludedItems, "excluded.xml");
            }
        }

        private void listBox2_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            int index = listBox2.IndexFromPoint(e.Location);
            if (index != -1)
            {
                string itemname = listBox2.Items[index].ToString();
                listBox2.Items.RemoveAt(index);
                listBox2.Sorted = true;

                WowItem item = excludedItems.Find(delegate(WowItem w) { return w.name == itemname; });
                excludedItems.Remove(item);
                listBox1.Items.Add(item.name);

                listBox1.Sorted = true;

                WowItem.Serialize(excludedItems, "excluded.xml");
            }
        }
        #endregion

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            //load profiles into combo box
            comboBox1.Items.Clear();
            profiles = WeightProfile.Deserialize("profiles_" + classes[comboBox2.SelectedIndex].Name + ".xml");
            for (int i = 0; i < profiles.Count; i++)
            {
                comboBox1.Items.Add(profiles[i].name);
            }
            if (profiles.Count > 0)
            {
                LoadProfileWeights(profiles[0]);
                comboBox1.SelectedIndex = 0;
            }
        }

        private void minilvl_SelectedIndexChanged(object sender, EventArgs e)
        {
            RepopulateExcludedLists();
        }

        private void maxilvl_SelectedIndexChanged(object sender, EventArgs e)
        {
            RepopulateExcludedLists();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            RepopulateExcludedLists();
        }

        private void RepopulateExcludedLists()
        {
            //add all filtered items back in, then remove any excluded.
            if (gearlist == null) //not initialised
                return;
            
            gearlist.AddRange(filteredItems);
            filteredItems.Clear();
            filteredItems.AddRange(gearlist.FindAll(delegate(WowItem w) { return w.ilvl != null && Int32.Parse(w.ilvl) < Int32.Parse(minilvl.Text); }));
            filteredItems.AddRange(gearlist.FindAll(delegate(WowItem w) { return w.ilvl != null && Int32.Parse(w.ilvl) > Int32.Parse(maxilvl.Text); }));
            gearlist.RemoveAll(delegate(WowItem w) { return w.ilvl != null && Int32.Parse(w.ilvl) < Int32.Parse(minilvl.Text); });
            gearlist.RemoveAll(delegate(WowItem w) { return w.ilvl != null && Int32.Parse(w.ilvl) > Int32.Parse(maxilvl.Text); });
            if (!includeHardModeItems.Checked)
            {
                filteredItems.AddRange(gearlist.FindAll(delegate(WowItem w) { return w.Heroic == true; }));
                gearlist.RemoveAll(delegate(WowItem w) { return w.Heroic == true; });
            }

            listBox1.Items.Clear();
            listBox2.Items.Clear();
            for (int i = 0; i < gearlist.Count; i++)
            {
                if (excludedItems.FindAll(delegate(WowItem w) { return w.name == gearlist[i].name; }).Count == 0)
                    listBox1.Items.Add(gearlist[i].name);
            }
            listBox1.Sorted = true;

            //add to 'excluded items list' all items which are excluded            
            for (int i = 0; i < excludedItems.Count; i++)
            {
                listBox2.Items.Add(excludedItems[i].name);
            }
            listBox2.Sorted = true;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            SaveProfileForm saveProfileForm = new SaveProfileForm(this);
            saveProfileForm.Show();
        }     
   
        public void SaveNewProfile(string profileName)
        {
            WeightProfile newProfile = new WeightProfile();
            newProfile.name = profileName;
            newProfile.targetHit = Int32.Parse(targetHitBox.Text);
            newProfile.spellpower = Double.Parse(spellpowerBox.Text);
            newProfile.haste = Double.Parse(hasteBox.Text);
            newProfile.crit = Double.Parse(critBox.Text);
            newProfile.spirit = Double.Parse(spiritBox.Text);
            newProfile.intel = Double.Parse(intelBox.Text);
            newProfile.stamina = Double.Parse(staminaBox.Text);
            newProfile.lostHit = Double.Parse(lostHitBox.Text);
            newProfile.t7_2pc = Double.Parse(t7_2pcBox.Text);
            newProfile.t7_4pc = Double.Parse(t7_4pcBox.Text);
            newProfile.t8_2pc = Double.Parse(t8_2pcBox.Text);
            newProfile.t8_4pc = Double.Parse(t8_4pcBox.Text);
            newProfile.t9_2pc = Double.Parse(t9_2pcBox.Text);
            newProfile.t9_4pc = Double.Parse(t9_4pcBox.Text);
            newProfile.t10_2pc = Double.Parse(t10_2pcBox.Text);
            newProfile.t10_4pc = Double.Parse(t10_4pcBox.Text);
            newProfile.includeT7 = includeT7.Checked;
            newProfile.includeT8 = includeT8.Checked;
            newProfile.includeT9 = includeT9.Checked;
            newProfile.includeT10 = includeT10.Checked; 
            newProfile.forceHit = forceHit.Checked;
            profiles.Add(newProfile);

            WeightProfile.Serialize(profiles, "profiles_"+classes[comboBox2.SelectedIndex].Name+".xml");

            //reload profiles
            comboBox1.Items.Clear();
            for (int i = 0; i < profiles.Count; i++)
            {
                comboBox1.Items.Add(profiles[i].name);
            }
            comboBox1.SelectedIndex = comboBox1.Items.Count - 1;
            LoadProfileWeights(profiles[profiles.Count-1]);
            MessageBox.Show("New profile Saved");
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //load profiles into combo box
            LoadProfileWeights(profiles[comboBox1.SelectedIndex]);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (profiles.Count == 0)
            {
                MessageBox.Show("No existing profile to update. Save as new instead.");
                return;
            }
            //save as existing
            profiles[comboBox1.SelectedIndex].targetHit = Int32.Parse(targetHitBox.Text);
            profiles[comboBox1.SelectedIndex].spellpower = Double.Parse(spellpowerBox.Text);
            profiles[comboBox1.SelectedIndex].haste = Double.Parse(hasteBox.Text);
            profiles[comboBox1.SelectedIndex].crit = Double.Parse(critBox.Text);
            profiles[comboBox1.SelectedIndex].spirit = Double.Parse(spiritBox.Text);
            profiles[comboBox1.SelectedIndex].intel = Double.Parse(intelBox.Text);
            profiles[comboBox1.SelectedIndex].stamina = Double.Parse(staminaBox.Text);
            profiles[comboBox1.SelectedIndex].lostHit = Double.Parse(lostHitBox.Text);
            profiles[comboBox1.SelectedIndex].t7_2pc = Double.Parse(t7_2pcBox.Text);
            profiles[comboBox1.SelectedIndex].t7_4pc = Double.Parse(t7_4pcBox.Text);
            profiles[comboBox1.SelectedIndex].t8_2pc = Double.Parse(t8_2pcBox.Text);
            profiles[comboBox1.SelectedIndex].t8_4pc = Double.Parse(t8_4pcBox.Text);
            profiles[comboBox1.SelectedIndex].t9_2pc = Double.Parse(t9_2pcBox.Text);
            profiles[comboBox1.SelectedIndex].t9_4pc = Double.Parse(t9_4pcBox.Text);
            profiles[comboBox1.SelectedIndex].t10_2pc = Double.Parse(t10_2pcBox.Text);
            profiles[comboBox1.SelectedIndex].t10_4pc = Double.Parse(t10_4pcBox.Text);
            profiles[comboBox1.SelectedIndex].includeT7 = includeT7.Checked;
            profiles[comboBox1.SelectedIndex].includeT8 = includeT8.Checked;
            profiles[comboBox1.SelectedIndex].includeT9 = includeT9.Checked;
            profiles[comboBox1.SelectedIndex].includeT10 = includeT10.Checked;
            profiles[comboBox1.SelectedIndex].forceHit = forceHit.Checked;
            
            WeightProfile.Serialize(profiles, "profiles_" + classes[comboBox2.SelectedIndex].Name + ".xml");

            MessageBox.Show("Profile Updated");
        }

        private void button5_Click(object sender, EventArgs e)
        {
            if (profiles.Count == 0) //nothing to delete
                return;

            //delete the current profile
            profiles.Remove(profiles[comboBox1.SelectedIndex]);
            WeightProfile.Serialize(profiles, "profiles_" + classes[comboBox2.SelectedIndex].Name + ".xml");

            //reload profiles
            comboBox1.Items.Clear();
            for (int i = 0; i < profiles.Count; i++)
            {
                comboBox1.Items.Add(profiles[i].name);
            }
            comboBox1.SelectedIndex = comboBox1.Items.Count - 1;
            if (profiles.Count > 0)
                LoadProfileWeights(profiles[profiles.Count - 1]);

            MessageBox.Show("Profile Deleted");
        }

        private void exportGearset_Click(object sender, EventArgs e)
        {
            /*List<WowItem> = optimiser.GearsetList
            WowItem.Serialize((optimiser.GearsetList)[0], "MyGearset.xml");
             * */
        }
    }
}
